/*
 * CircuitAdapter.cpp
 *
 * Created on: 06-05-2014
 *     Author: A.W. Janisse
 *
 * Version 1.0: 24-05-2014, Final release
 */

#include "CircuitAdapter.h"
#include "Circuit.h"
#include "Gate.h"

Circuit circuit;

string MarshalAsString(const char* text)
{
    // builds a copy of the text in a new string
    string result = "";
    int i=0;
    while (text[i] != '\0')
    {
        result += text[i];
        i++;
    }
    return result;
}

bool _addGate(int x, int y, const char* type)
{
    circuit.addGate(x, y, MarshalAsString(type));
    return true;
}

bool _removeGate(int x, int y)
{
    return circuit.removeGate(x, y);
}

bool _addConnection(int x1, int y1, int x2, int y2)
{
    return circuit.addConnection(x1,y1,x2,y2);
}

bool _removeConnection(int x1, int y1, int x2, int y2)
{
    return circuit.removeConnection(x1,y1,x2,y2);
}

const char* _getDrawingInstruction()
{
    return circuit.getDrawingInstruction().c_str();
}

const char* _serialize()
{
    return circuit.serialize().c_str();
}

bool _deserialize(const char* serializedCircuit)
{
    return circuit.deserialize(MarshalAsString(serializedCircuit));
}

void _clearCircuit()
{
    circuit.clearCircuit();
}


